import { keepIntactOrderType } from '@/store/type/index'
import { queryPreserveList } from '@/request/api'

const getTabs = (data) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(['1', '2'])
    }, 1000)
  })
}
const keepIntactOrderAction = {
  getKeepOrderList() {
    // redux-thunk 中间件写法
    return async (dispatch) => {
      const {
        data: { records },
      } = await queryPreserveList({ pageSize: 10, pageNum: 1 })
      dispatch({ type: keepIntactOrderType.setAllList, payload: records })
    }
  },
  getTabs() {
    // redux-thunk 中间件写法
    return async (dispatch) => {
      const res = await getTabs()
      dispatch({ type: keepIntactOrderType.setTabs, payload: res })
      dispatch({ type: keepIntactOrderType.setTabActive, payload: res[0] })
      dispatch({ type: keepIntactOrderType.setList })
    }
  },
  //   async getTabs() {
  //     // redux-promise 中间件写法 简化异步代码
  //     const res = await getTabs()
  //     return { type: keepIntactOrderType.setTabs, payload: res }
  //   },
  getTableData() {
    return { type: keepIntactOrderType.setList }
  },
  setTabActive(payload) {
    return { type: keepIntactOrderType.setTabActive, payload }
  },
  changeRowApplicationDate(payload) {
    return { type: keepIntactOrderType.changeRowApplicationDate, payload }
  },
}
export default keepIntactOrderAction
